//
//  MyModel.m
//  工厂模式
//
//  Created by clz on 2019/10/7.
//  Copyright © 2019 clz. All rights reserved.
//

#import "MyModel.h"
#import "Model01.h"
#import "Model02.h"

@implementation MyModel

+(instancetype)initWithDictionary:(NSDictionary *)dictionary{
    //先使用父类创建对象；
    MyModel *rootModel = nil;
    
    //根据字典中的key对应的数据初始化不同的子类对象并将其返回给父类
    if ([dictionary[@"type"] isEqualToString:@"1"]) {
        rootModel = [[Model01 alloc]init];
    }else if ([dictionary[@"type"] isEqualToString:@"2"]){
        rootModel = [[Model02 alloc]init];
    }
    
    [rootModel setValueWithDic:dictionary];
    
    return rootModel;
}

- (void)setValueWithDic:(NSDictionary *)dic{
    
}

@end
